﻿using Modbus.Device;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Zhaoxi.CustomerControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {

        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = this;

            TcpClient tcpClient = new TcpClient();
            tcpClient.Connect("192.168.2.1", 502);
            Modbus.Device.ModbusIpMaster master = ModbusIpMaster.CreateIp(tcpClient);
            ushort[] values = master.ReadHoldingRegisters(1, 0, 1);
            this.Value = values[0] * 0.1;/// 如果正常   页面上的结果应该是111
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        private double _value;

        public double Value
        {
            get { return _value; }
            set
            {
                _value = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
            }
        }

    }
}
